<?php

namespace Tool;

class CryptAES
{
    const  IV = 'AESAPPCLIENT_KEY';//16或16的倍数长个char

    const key = 'JF_2022610000000';

//$privateKey是加密 解密需要的密钥
    public static function aesEncode($data, $privateKey = self::key, $iv = self::IV)
    {

        $encrypted = openssl_encrypt($data, "AES-128-CBC", $privateKey, OPENSSL_RAW_DATA, $iv);
        return rtrim((base64_encode($encrypted)));
    }

    public static function aesDecode($data, $privateKey = self::key, $iv = self::IV)
    {
        $decrypted = openssl_decrypt(base64_decode($data), "AES-128-CBC", $privateKey, OPENSSL_RAW_DATA, $iv);
        return rtrim($decrypted);
    }
}


